package cn.ac.iscas.dba;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.bson.BasicBSONObject;

import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;

public class Test {
	public static void main(String[] args){
		try{
			Mongo m = new Mongo(Constants.host);
			DB db = m.getDB( "swallow" );
			DBCollection coll = db.getCollection("taobao1");
	        BasicDBObject doc = new BasicDBObject();

	        doc.put("name", "MongoDB1");
	        doc.put("type", "database");
	        doc.put("count", 1);

	        BasicDBObject info = new BasicDBObject();

	        info.put("x", 203);
	        info.put("y", 102);

	        doc.put("info", info);

	        coll.insert(doc);
//			DBObject myDoc = coll.findOne();
//			System.out.println(myDoc);
//			for (int i=0; i < 100; i++) {
//			    coll.insert(new BasicDBObject().append("i", i));
//			}
			DBCursor cur = coll.find();

	        while(cur.hasNext()) {
	            System.out.println(cur.next());
	        }
//			BasicDBObject query = new BasicDBObject();
//
//			query.put("i", new BasicDBObject("$gt", 20).append("$lte", 30)); 
//
//	        cur = coll.find(query);
//
//	        while(cur.hasNext()) {
//	            System.out.println(cur.next());
//	        }
//			coll.createIndex(new BasicDBObject("i", 1));
//			List<DBObject> list = coll.getIndexInfo();
//
//	        for (DBObject o : list) {
//	            System.out.println(o);
//	        }'
//			HashMap s = new HashMap();
//			s.put("name", "MongoDB");
//			s.put("price", 1000);
//			Set set = s.entrySet();        
//			Iterator i = set.iterator();
//			BasicDBObject info = new BasicDBObject();
//			while(i.hasNext()){
//			     Map.Entry<String, Object> entry1=(Map.Entry <String, Object>)i.next();
//			     info.put(entry1.getKey(), entry1.getValue());
//			}
//			coll.insert(info);
			
		} catch (Exception e){
			e.printStackTrace();
		}
		
	}
}
